#!/bin/bash

#
# svnunk -- by Dario Berzano <dario.berzano@gmail.com>
#
# Part of the lfscripts suite -- http://lfscripts.googecode.com/
#
# Removes files not under SVN version control (those that appear with a leading
# question mark when doing svn status) under the given SVN tree (defaults to
# current directory). It also removes files explicitly ignored by SVN (by means
# of the svn:ignore property.
#

export SVNDIR="$1"
[ "$SVNDIR" ==  "" ] && SVNDIR="."

MSG="\n\033[1;41m\033[1;37m!!! Every file and directory not under version "
MSG="${MSG}control will be removed !!!\033[m\n\nIs this what you want? "
MSG="${MSG}\n\nType \"Yes\" by respecting capitalisation: "

echo -ne "${MSG}"
read R

if [ "$R" == "Yes" ]; then
  svn status --no-ignore -- "$SVNDIR" | egrep '^\?|^I' | awk '{print $2}' | \
  while read F; do
    rm -rf "$F"
  done
else
  echo "Operation aborted"
fi
